/** <a href="http://www.cpupk.com/decompiler">Eclipse Class Decompiler</a> plugin, Copyright (c) 2017 Chen Chao. **/
package com.minierp.controller;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.minierp.bean.BusinessBillBean;
import com.minierp.bean.QueryParameterBean;
import com.minierp.bean.QueryResult;
import com.minierp.bean.ReceiveBillBean;
import com.minierp.bean.UserBean;
import com.minierp.bean.UserStatus;
import com.minierp.dao.AdjustBillDao;
import com.minierp.dao.BankAccountBalanceDao;
import com.minierp.dao.BankAccountDao;
import com.minierp.dao.BankAccountDetailDao;
import com.minierp.dao.BusinessBillDao;
import com.minierp.dao.CodeRuleDao;
import com.minierp.dao.DepartmentDao;
import com.minierp.dao.FinanceDetailDao;
import com.minierp.dao.IdGenerator;
import com.minierp.dao.PayModeDao;
import com.minierp.dao.QueryDao;
import com.minierp.dao.ReceiveBillDao;
import com.minierp.dao.ReceiveBillItemDao;
import com.minierp.dao.SerialNumberDao;
import com.minierp.dao.TallySetDao;
import com.minierp.err.NotAllowException;
import com.minierp.err.PermissionDennyException;
import com.minierp.helper.EncCommonHelper;
import com.minierp.helper.EncInterceptorHelper;
import com.minierp.helper.EncReceiveBillMACtrHelper;
import com.minierp.helper.PageHelper;
import com.minierp.model.BankAccount;
import com.minierp.model.BusinessBill;
import com.minierp.model.BusinessBillExt;
import com.minierp.model.CodeRule;
import com.minierp.model.Department;
import com.minierp.model.EnterpriseInfo;
import com.minierp.model.Establishment;
import com.minierp.model.ReceiveBill;
import com.minierp.model.ReceiveBillItem;
import com.minierp.model.TallySet;
import com.minierp.service.ReceiveBillService;
import com.minierp.view.BackCostListExcelView;
import com.minierp.view.ReceiveBillItemListExcelView;
import com.minierp.view.ReceiveBillListExcelView;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.sql.DataSource;
import org.springframework.dao.CannotAcquireLockException;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;

public class ReceiveBillMACtr extends MultiActionController {
	private String dialogSuccessView;
	private String listForExamineView;
	private String infoForExamineView;
	private String listForUnExamineView;
	private String infoForUnExamineView;
	private String searchResultView;
	private String financeListForClientView;
	private String itemListForBusinessBillView;
	private String listForEstablishmentView;
	private String printView;
	private String printLittleView;
	private String listForCancelView;
	private String infoForCancelView;
	private String backCostListView;
	private String backCostListPrintView;
	private String itemSearchResultView;
	private BusinessBillDao businessBillDao;
	private ReceiveBillDao receiveBillDao;
	private AdjustBillDao adjustBillDao;
	private ReceiveBillItemDao receiveBillItemDao;
	private DepartmentDao departmentDao;
	private BankAccountBalanceDao bankAccountBalanceDao;
	private BankAccountDetailDao bankAccountDetailDao;
	private PayModeDao payModeDao;
	private TallySetDao tallySetDao;
	private BankAccountDao bankAccountDao;
	private FinanceDetailDao financeDetailDao;
	private QueryDao queryDao;
	private CodeRuleDao codeRuleDao;
	private SerialNumberDao serialNumberDao;
	private IdGenerator idGenerator;
	private ReceiveBillService receiveBillService;
	private DataSource dataSource;

	public SerialNumberDao getSerialNumberDao() {
		return this.serialNumberDao;
	}

	public void setSerialNumberDao(SerialNumberDao serialNumberDao) {
		this.serialNumberDao = serialNumberDao;
	}

	public String getPrintLittleView() {
		return this.printLittleView;
	}

	public void setPrintLittleView(String printLittleView) {
		this.printLittleView = printLittleView;
	}

	public String getItemSearchResultView() {
		return this.itemSearchResultView;
	}

	public void setItemSearchResultView(String itemSearchResultView) {
		this.itemSearchResultView = itemSearchResultView;
	}

	public ModelAndView handleExamine(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		ModelAndView mv = new ModelAndView(this.dialogSuccessView);
		UserBean ub = EncCommonHelper.getCurrentUserAccount(request);
		String idStr = request.getParameter("id_str");
		String flag = request.getParameter("flag");
		boolean examined = false;
		if (flag != null && flag.equals("1")) {
			examined = true;
		}

		String[] arr = idStr.split(";");
		boolean num = false;
		String msg;
		byte arg18;
		if (!examined) {
			if (!EncCommonHelper.checkPrivilege(request, "RECE_UN_EXAM")) {
				throw new Exception("Permission deny!");
			}

			try {
				for (int examinerId = 0; examinerId < arr.length; ++examinerId) {
					this.receiveBillService.txUnExamine(
							Long.parseLong(arr[examinerId]),
							this.receiveBillDao, this.receiveBillItemDao,
							this.businessBillDao, this.adjustBillDao,
							this.bankAccountBalanceDao,
							this.bankAccountDetailDao, this.financeDetailDao,
							this.idGenerator, ub);
				}

				msg = "反审核成功";
			} catch (NotAllowException arg16) {
				msg = arg16.getMessage();
			} catch (CannotAcquireLockException arg17) {
				msg = "事务冲突故障，请重新操作！";
			}

			arg18 = 1;
		} else {
			if (!EncCommonHelper.checkPrivilege(request, "RECE_EXAM")) {
				throw new Exception("Permission deny!");
			}

			long arg19 = ub.getStaffer().getId();
			String examinerName = ub.getStaffer().getStafferName();

			try {
				for (int w = 0; w < arr.length; ++w) {
					this.receiveBillService.txExamine(Long.parseLong(arr[w]),
							this.receiveBillDao, this.receiveBillItemDao,
							this.businessBillDao, this.adjustBillDao, arg19,
							examinerName, this.bankAccountBalanceDao,
							this.idGenerator);
				}

				msg = "审核成功";
			} catch (NotAllowException arg14) {
				msg = arg14.getMessage();
			} catch (CannotAcquireLockException arg15) {
				msg = "事务冲突故障，请重新操作！";
			}

			arg18 = 1;
		}

		mv.addObject("returnValue", String.valueOf(arg18));
		EncCommonHelper.setAlertMessage(request, msg);
		return mv;
	}

	public ModelAndView handleListForExamine(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		if (!EncCommonHelper.checkPrivilege(request, "RECE_EXAM")) {
			throw new PermissionDennyException("Permission Denny");
		} else {
			ModelAndView mv = new ModelAndView(this.listForExamineView);
			String searchKey = request.getParameter("search_key");
			String tsId = request.getParameter("ts_id");
			UserBean ub = EncCommonHelper.getCurrentUserAccount(request);
			if (tsId == null || tsId.equals("")) {
				tsId = String.valueOf(ub.getUser().getDfTsId());
			}

			long managerId = 0L;
			if (EncCommonHelper.checkPurePrivilege(request, "BUSI_SELF")) {
				managerId = ub.getStaffer().getId();
			}

			Date allowStart = null;
			if (EncCommonHelper.checkPurePrivilege(request, "NO_EARL_DATA")) {
				allowStart = EncCommonHelper.getEarlDataDate(request);
			}

			List tsList = PageHelper.getTallySetList(this.tallySetDao, ub);
			int perPageNum = EncCommonHelper.getPageSize(request);
			int total = this.receiveBillDao.getListCount(searchKey, false,
					Long.parseLong(tsId), ub, managerId, allowStart);
			int pageno = EncCommonHelper.getCurrentPageIndex(request, total,
					perPageNum);
			int startIndex = (pageno - 1) * perPageNum;
			List list = this.receiveBillDao.getList(searchKey, false,
					Long.parseLong(tsId), ub, managerId, allowStart,
					startIndex, perPageNum);
			mv.addObject("qr", EncCommonHelper.parseQueryResult(list, total,
					perPageNum, pageno));
			mv.addObject("searchKey", searchKey);
			mv.addObject(
					"costTotal",
					this.receiveBillDao.getListCost(searchKey, false,
							Long.parseLong(tsId), ub, managerId, allowStart));
			mv.addObject("tsId", tsId);
			mv.addObject("tsList", tsList);
			return mv;
		}
	}

	public ModelAndView handleInfoForExamine(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		ModelAndView mv = new ModelAndView(this.infoForExamineView);
		String id = request.getParameter("id");
		this.getReceiveBill(mv, Long.parseLong(id));
		return mv;
	}

	public ModelAndView handleListForUnExamine(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		if (!EncCommonHelper.checkPrivilege(request, "RECE_UN_EXAM")) {
			throw new PermissionDennyException("Permission Denny");
		} else {
			ModelAndView mv = new ModelAndView(this.listForUnExamineView);
			String searchKey = request.getParameter("search_key");
			String tsId = request.getParameter("ts_id");
			UserBean ub = EncCommonHelper.getCurrentUserAccount(request);
			if (tsId == null || tsId.equals("")) {
				tsId = String.valueOf(ub.getUser().getDfTsId());
			}

			long managerId = 0L;
			if (EncCommonHelper.checkPurePrivilege(request, "BUSI_SELF")) {
				managerId = ub.getStaffer().getId();
			}

			Date allowStart = null;
			if (EncCommonHelper.checkPurePrivilege(request, "NO_EARL_DATA")) {
				allowStart = EncCommonHelper.getEarlDataDate(request);
			}

			List tsList = PageHelper.getTallySetList(this.tallySetDao, ub);
			int perPageNum = EncCommonHelper.getPageSize(request);
			int total = this.receiveBillDao.getListCount(searchKey, true,
					Long.parseLong(tsId), ub, managerId, allowStart);
			int pageno = EncCommonHelper.getCurrentPageIndex(request, total,
					perPageNum);
			int startIndex = (pageno - 1) * perPageNum;
			List list = this.receiveBillDao.getList(searchKey, true,
					Long.parseLong(tsId), ub, managerId, allowStart,
					startIndex, perPageNum);
			mv.addObject("qr", EncCommonHelper.parseQueryResult(list, total,
					perPageNum, pageno));
			mv.addObject("searchKey", searchKey);
			mv.addObject("tsId", tsId);
			mv.addObject("tsList", tsList);
			return mv;
		}
	}

	public ModelAndView handleInfoForUnExamine(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		ModelAndView mv = new ModelAndView(this.infoForUnExamineView);
		String id = request.getParameter("id");
		this.getReceiveBill(mv, Long.parseLong(id));
		return mv;
	}

	public ModelAndView handleListForCancel(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		if (!EncCommonHelper.checkPrivilege(request, "RECE_CANC")) {
			throw new PermissionDennyException("Permission Denny");
		} else {
			ModelAndView mv = new ModelAndView(this.listForCancelView);
			String searchKey = request.getParameter("search_key");
			String tsId = request.getParameter("ts_id");
			UserBean ub = EncCommonHelper.getCurrentUserAccount(request);
			if (tsId == null || tsId.equals("")) {
				tsId = String.valueOf(ub.getUser().getDfTsId());
			}

			long managerId = 0L;
			if (EncCommonHelper.checkPurePrivilege(request, "BUSI_SELF")) {
				managerId = ub.getStaffer().getId();
			}

			Date allowStart = null;
			if (EncCommonHelper.checkPurePrivilege(request, "NO_EARL_DATA")) {
				allowStart = EncCommonHelper.getEarlDataDate(request);
			}

			List tsList = PageHelper.getTallySetList(this.tallySetDao, ub);
			int perPageNum = EncCommonHelper.getPageSize(request);
			int total = this.receiveBillDao.getListCount(searchKey,
					Long.parseLong(tsId), ub, managerId, allowStart);
			int pageno = EncCommonHelper.getCurrentPageIndex(request, total,
					perPageNum);
			int startIndex = (pageno - 1) * perPageNum;
			List list = this.receiveBillDao.getList(searchKey,
					Long.parseLong(tsId), ub, "", managerId, allowStart,
					startIndex, perPageNum);
			mv.addObject("qr", EncCommonHelper.parseQueryResult(list, total,
					perPageNum, pageno));
			mv.addObject("searchKey", searchKey);
			mv.addObject("tsId", tsId);
			mv.addObject("tsList", tsList);
			return mv;
		}
	}

	public ModelAndView handleInfoForCancel(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		ModelAndView mv = new ModelAndView(this.infoForCancelView);
		String id = request.getParameter("id");
		this.getReceiveBill(mv, Long.parseLong(id));
		return mv;
	}

	public ModelAndView handleCancel(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		ModelAndView mv = new ModelAndView(this.dialogSuccessView);
		UserBean ub = EncCommonHelper.getCurrentUserAccount(request);
		if (!EncCommonHelper.checkPrivilege(request, "RECE_CANC")) {
			throw new Exception("Permission deny!");
		} else {
			String id = request.getParameter("id");
			String reason = request.getParameter("reason");
			String msg = "作废成功！";

			try {
				this.receiveBillService.txCancel(Long.parseLong(id), reason,
						this.receiveBillDao, this.receiveBillItemDao,
						this.businessBillDao, this.adjustBillDao, ub,
						this.bankAccountBalanceDao, this.bankAccountDetailDao,
						this.financeDetailDao, this.idGenerator);
			} catch (NotAllowException arg8) {
				msg = arg8.getMessage();
			} catch (CannotAcquireLockException arg9) {
				msg = "事务冲突故障，请重新操作！";
			}

			mv.addObject("returnValue", id);
			EncCommonHelper.setAlertMessage(request, msg);
			return mv;
		}
	}

	private void getReceiveBill(ModelAndView mv, long id) {
		ReceiveBill receiveBill = (ReceiveBill) this.receiveBillDao.get(
				ReceiveBill.class, id);
		ReceiveBillBean form = new ReceiveBillBean();
		form.setReceiveBill(receiveBill);
		List itemList = this.receiveBillItemDao
				.getListByReceiveBill(receiveBill.getId());
		form.setItems(itemList);
		if (receiveBill != null) {
			Establishment beginIndex = (Establishment) this.businessBillDao
					.get(Establishment.class, receiveBill.getClientId());
			if (beginIndex != null) {
				form.setClientName(beginIndex.getEstName());
			}

			if (receiveBill.getDepartmentId() != 0L) {
				Department d = (Department) this.businessBillDao.get(
						Department.class, receiveBill.getDepartmentId());
				if (d != null) {
					form.setDepartmentName(d.getDepartmentName());
				}
			}

			if (receiveBill.getBankAccountId() != 0L) {
				BankAccount d1 = (BankAccount) this.businessBillDao.get(
						BankAccount.class, receiveBill.getBankAccountId());
				if (d1 != null) {
					form.setBankAccountName(d1.getBankName());
				}
			}

			if (receiveBill.getTallySetId() != 0L) {
				TallySet d2 = (TallySet) this.businessBillDao.get(
						TallySet.class, receiveBill.getTallySetId());
				if (d2 != null) {
					form.setTallySetName(d2.getTitle());
				}
			}
		}

		mv.addObject("record", form);
		if (receiveBill.getAttachFile() != null
				&& !receiveBill.getAttachFile().equals("")) {
			int beginIndex1 = receiveBill.getAttachFile().lastIndexOf("/");
			mv.addObject("attFile",
					receiveBill.getAttachFile().substring(beginIndex1 + 1));
		}

	}

	public ModelAndView handleSearchResult(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		if (!EncCommonHelper.checkPrivilege(request, "RECE_BILL_SEAR")) {
			throw new PermissionDennyException("Permission Denny");
		} else {
			ModelAndView mv = new ModelAndView(this.searchResultView);
			String contentType = request.getParameter("content_type");
			QueryParameterBean b = EncReceiveBillMACtrHelper
					.handleSearchResult(request, this.dataSource);
			String[] countObjs = new String[]{"sum(b.cost)"};
			QueryResult qr;
			if (contentType != null && contentType.equals("EXCEL")) {
				qr = this.queryDao.doQuery(b.getQParas(), b.getOParas(),
						(String[]) null, b.getShortNameMap(), b.getRetObjs(),
						countObjs);
			} else {
				qr = this.queryDao.doQuery(b.getCurrentPage(), b.getPageSize(),
						b.getQParas(), b.getOParas(), (String[]) null,
						b.getShortNameMap(), b.getRetObjs(), countObjs);
			}

			List bankAccountList = this.bankAccountDao.getList("", "");
			if (contentType != null && contentType.equals("EXCEL")) {
				HashMap arg16 = new HashMap();
				arg16.put("list", qr.getList());
				arg16.put("baList", bankAccountList);
				arg16.put("collectTotal", qr.getExtCount()[0]);
				ReceiveBillListExcelView arg18 = new ReceiveBillListExcelView();
				return new ModelAndView(arg18, arg16);
			} else {
				for (int ent = 0; ent < qr.getList().size(); ++ent) {
					Object[] ub = (Object[]) qr.getList().get(ent);
					ReceiveBillBean bean = new ReceiveBillBean();
					ReceiveBill bill = (ReceiveBill) ub[0];
					bean.setReceiveBill(bill);
					String baName = "";
					if (bill.getBankAccountId() != 0L) {
						for (int j = 0; j < bankAccountList.size(); ++j) {
							BankAccount ba = (BankAccount) bankAccountList
									.get(j);
							if (ba.getId() == bill.getBankAccountId()) {
								baName = ba.getBankName();
								if (ba.getAccountName() != null
										&& !ba.getAccountName().equals("")) {
									baName = baName + "(" + ba.getAccountName()
											+ ")";
								}
							}
						}
					}

					bean.setBankAccountName(baName);
					ub[0] = bean;
				}

				mv.addObject("qr", qr);
				mv.addAllObjects(b.getParameters());
				mv.addObject("collectTotal", qr.getExtCount()[0]);
				mv.addObject("departmentList", this.departmentDao.getList(true));
				EnterpriseInfo arg15 = EncCommonHelper
						.getEnterpriseInfo(request);
				UserBean arg17 = EncCommonHelper.getCurrentUserAccount(request);
				mv.addObject("myBaList", PageHelper.parseBaList(
						bankAccountList, arg15, arg17, 0L, 0L));
				mv.addObject("tsList",
						PageHelper.getTallySetList(this.tallySetDao, arg17));
				return mv;
			}
		}
	}

	public ModelAndView handleFinanceListForClient(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		ModelAndView mv = new ModelAndView(this.financeListForClientView);
		String clientId = request.getParameter("client_id");
		List bList = this.businessBillDao.getList(Long.parseLong(clientId),
				true, EncCommonHelper.getCurrentUserAccount(request));
		List rList = this.receiveBillDao.getList(Long.parseLong(clientId),
				true, EncCommonHelper.getCurrentUserAccount(request));
		List aList = this.adjustBillDao.getList("BUSINESS_BILL",
				Long.parseLong(clientId), true,
				EncCommonHelper.getCurrentUserAccount(request));
		mv.addObject("businessBillList", bList);
		mv.addObject("receiveBillList", rList);
		mv.addObject("adjustBillList", aList);
		mv.addObject(
				"est",
				this.receiveBillDao.get(Establishment.class,
						Long.parseLong(clientId)));
		return mv;
	}

	public ModelAndView handleItemListForBusinessBill(
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		ModelAndView mv = new ModelAndView(this.itemListForBusinessBillView);
		String id = request.getParameter("id");
		BusinessBill businessBill = (BusinessBill) this.receiveBillDao.get(
				BusinessBill.class, Long.parseLong(id));
		mv.addObject("businessBill", businessBill);
		List items = this.receiveBillItemDao.getListByBusinessBill(Long
				.parseLong(id));
		mv.addObject("items", items);
		return mv;
	}

	public ModelAndView handlePrint(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String id = request.getParameter("id");
		String printDetail = request.getParameter("print_detail");
		ModelAndView mv;
		if (printDetail != null && printDetail.equals("L")) {
			mv = new ModelAndView(this.printLittleView);
			ReceiveBill bill = (ReceiveBill) this.receiveBillDao.get(
					ReceiveBill.class, Long.parseLong(id));
			Establishment est = (Establishment) this.receiveBillDao.get(
					Establishment.class, bill.getClientId());
			List items = this.receiveBillItemDao.getListForPrinLitt(bill
					.getId());
			BigDecimal remaCost = new BigDecimal(0);

			for (int i = 0; i < items.size(); ++i) {
				Object[] objs = (Object[]) items.get(i);
				ReceiveBillItem it = (ReceiveBillItem) objs[0];
				remaCost = remaCost.add(it.getRemainCost().subtract(
						it.getThisCost()));
			}

			mv.addObject("bill", bill);
			mv.addObject("items", items);
			mv.addObject("estName", est.getEstName());
			mv.addObject("remaCost", remaCost);
		} else {
			mv = new ModelAndView(this.printView);
			this.getReceiveBill(mv, Long.parseLong(id));
			mv.addObject("codeRule", this.codeRuleDao.get("RECEIVE_BILL"));
			mv.addObject("printDetail", printDetail);
		}

		mv.addObject("retVal", request.getParameter("ret_val"));
		return mv;
	}

	public ModelAndView handleListForEstablishment(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		ModelAndView mv = new ModelAndView(this.listForEstablishmentView);
		QueryParameterBean b = EncReceiveBillMACtrHelper
				.handleListForEstablishment(request, this.dataSource);
		String[] countObjs = new String[]{"sum(b.cost)"};
		QueryResult qr = this.queryDao.doQuery(b.getCurrentPage(),
				b.getPageSize(), b.getQParas(), b.getOParas(), (String[]) null,
				b.getShortNameMap(), b.getRetObjs(), countObjs);
		mv.addObject("qr", qr);
		mv.addObject("costTotal", qr.getExtCount()[0]);
		String id = request.getParameter("id");
		mv.addObject("id", id);
		mv.addObject("est", this.receiveBillDao.get(Establishment.class,
				Long.parseLong(id)));
		return mv;
	}

	public ModelAndView handleBackCostList(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		if (!EncCommonHelper.checkPrivilege(request, "BUSI_BACK_SEAR")) {
			throw new PermissionDennyException("Permission Denny");
		} else {
			String contentType = request.getParameter("content_type");
			String cbBackType = request.getParameter("cb_back_type");
			String backType = request.getParameter("back_type");
			boolean needImprest = true;
			boolean needReceive = true;
			if (cbBackType != null && cbBackType.equals("1")) {
				if (backType != null && backType.equals("RECEIVE")) {
					needImprest = false;
				}

				if (backType != null && backType.equals("IMPREST")) {
					needReceive = false;
				}
			}

			List depList = this.departmentDao.getList(true);
			List bankAccountList = this.bankAccountDao.getList("", "");
			BigDecimal total = new BigDecimal(0);
			BigDecimal imprestTotal = new BigDecimal(0);
			BigDecimal receiveTotal = new BigDecimal(0);
			QueryParameterBean b = null;
			List recList = null;
			Department dep;
			if (needReceive) {
				b = EncReceiveBillMACtrHelper.handleReceiveBillListForBackCost(
						request, this.dataSource);
				recList = this.queryDao.doQuery(b.getQParas(), b.getOParas(),
						(String[]) null, b.getShortNameMap(), b.getRetObjs(),
						(String[]) null).getList();

				for (int impList = 0; impList < recList.size(); ++impList) {
					Object[] mv = (Object[]) recList.get(impList);
					ReceiveBill ent = (ReceiveBill) mv[0];
					ReceiveBillBean ub = new ReceiveBillBean();
					ub.setReceiveBill(ent);
					total = total.add(ent.getCost());
					receiveTotal = receiveTotal.add(ent.getCost());

					for (int bean = 0; bean < depList.size(); ++bean) {
						dep = (Department) depList.get(bean);
						if (dep.getId() == ent.getDepartmentId()) {
							ub.setDepartmentName(dep.getDepartmentName());
							break;
						}
					}

					mv[0] = ub;
				}
			}

			List arg21 = null;
			if (needImprest) {
				b = EncReceiveBillMACtrHelper
						.handleBusinessBillListForBackCost(request,
								this.dataSource);
				arg21 = this.queryDao.doQuery(b.getQParas(), b.getOParas(),
						(String[]) null, b.getShortNameMap(), b.getRetObjs(),
						(String[]) null).getList();

				for (int arg22 = 0; arg22 < arg21.size(); ++arg22) {
					Object[] arg24 = (Object[]) arg21.get(arg22);
					BusinessBill arg28 = (BusinessBill) arg24[0];
					BusinessBillBean arg30 = new BusinessBillBean();
					arg30.setBusinessBill(arg28);
					total = total.add(arg28.getImprest());
					imprestTotal = imprestTotal.add(arg28.getImprest());

					for (int j = 0; j < depList.size(); ++j) {
						dep = (Department) depList.get(j);
						if (dep.getId() == arg28.getDepartmentId()) {
							arg30.setDepartmentName(dep.getDepartmentName());
							break;
						}
					}

					arg24[0] = arg30;
				}
			}

			if (contentType != null && contentType.equals("EXCEL")) {
				HashMap arg26 = new HashMap();
				arg26.put("receiveList", recList);
				arg26.put("imprestList", arg21);
				arg26.put("total", total);
				arg26.put("imprestTotal", imprestTotal);
				arg26.put("receiveTotal", receiveTotal);
				arg26.put("bankAccountList", bankAccountList);
				BackCostListExcelView arg27 = new BackCostListExcelView();
				return new ModelAndView(arg27, arg26);
			} else {
				ModelAndView arg23;
				if (contentType != null && contentType.equals("PRINT")) {
					arg23 = new ModelAndView(this.backCostListPrintView);
				} else {
					arg23 = new ModelAndView(this.backCostListView);
				}

				arg23.addObject("cbBackType", cbBackType);
				arg23.addObject("backType", backType);
				arg23.addObject("receiveList", recList);
				arg23.addObject("imprestList", arg21);
				if (b != null) {
					arg23.addAllObjects(b.getParameters());
				}

				arg23.addObject("total", total);
				arg23.addObject("imprestTotal", imprestTotal);
				arg23.addObject("receiveTotal", receiveTotal);
				arg23.addObject("departmentList", depList);
				arg23.addObject("bankAccountList", bankAccountList);
				EnterpriseInfo arg25 = EncCommonHelper
						.getEnterpriseInfo(request);
				UserBean arg29 = EncCommonHelper.getCurrentUserAccount(request);
				arg23.addObject("myBaList", PageHelper.parseBaList(
						bankAccountList, arg25, arg29, 0L, 0L));
				arg23.addObject("tsList",
						PageHelper.getTallySetList(this.tallySetDao, arg29));
				return arg23;
			}
		}
	}

	public ModelAndView handleItemSearchResult(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		if (!EncCommonHelper.checkPrivilege(request, "RECE_ITEM_SEAR")) {
			throw new PermissionDennyException("Permission Denny");
		} else {
			ModelAndView mv = new ModelAndView(this.itemSearchResultView);
			String contentType = request.getParameter("content_type");
			QueryParameterBean b = EncReceiveBillMACtrHelper
					.handleItemSearchResult(request, this.dataSource);
			String[] countObjs = new String[]{"sum(i.thisCost)"};
			List bankAccountList = this.bankAccountDao.getList("", "");
			if (contentType != null && contentType.equals("EXCEL")) {
				HashMap qr1 = new HashMap();
				QueryResult ub1 = this.queryDao.doQuery(b.getQParas(),
						b.getOParas(), (String[]) null, b.getShortNameMap(),
						b.getRetObjs(), countObjs);
				qr1.put("list", ub1.getList());
				qr1.put("costTotal", ub1.getExtCount()[0]);
				qr1.put("baList", bankAccountList);
				ReceiveBillItemListExcelView ent1 = new ReceiveBillItemListExcelView();
				return new ModelAndView(ent1, qr1);
			} else {
				QueryResult qr = this.queryDao.doQuery(b.getCurrentPage(),
						b.getPageSize(), b.getQParas(), b.getOParas(),
						(String[]) null, b.getShortNameMap(), b.getRetObjs(),
						countObjs);
				mv.addAllObjects(b.getParameters());
				mv.addObject("qr", qr);
				mv.addObject("costTotal", qr.getExtCount()[0]);
				UserBean ub = EncCommonHelper.getCurrentUserAccount(request);
				mv.addObject("tsList",
						PageHelper.getTallySetList(this.tallySetDao, ub));
				EnterpriseInfo ent = EncCommonHelper.getEnterpriseInfo(request);
				mv.addObject("myBaList", PageHelper.parseBaList(
						bankAccountList, ent, ub, 0L, 0L));
				mv.addObject("baList", bankAccountList);
				return mv;
			}
		}
	}

	public ModelAndView handleAppBcList(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		HashMap map = new HashMap();
		UserStatus s = EncInterceptorHelper.checkAppUserSignon(request);
		UserBean ub = s.getUserBean();
		String json;
		if (ub == null) {
			map.put("status", "NO_LOGIN");
			map.put("errMag", "");
		} else if (!EncCommonHelper.checkPrivilege(request, "BUSI_BACK_SEAR")) {
			map.put("status", "ERROR");
			map.put("errMag", "您还没有此功能的使用权限，请确认返回！");
		} else {
			try {
				String mapper = request.getParameter("est_name");
				json = request.getParameter("start_date");
				String out = request.getParameter("end_date");
				String bt = request.getParameter("bt");
				String tsIdStr = request.getParameter("ts_id");
				String showPrev = request.getParameter("show_prev");
				String initQuer = request.getParameter("init_quer");
				long mngId = 0L;
				long tsId = 0L;
				if (tsIdStr != null && !tsIdStr.equals("")) {
					tsId = Long.parseLong(tsIdStr);
				}

				if (EncCommonHelper.checkPurePrivilege(request, "BUSI_SELF")) {
					mngId = ub.getStaffer().getId();
				}

				Date allowStart = null;
				Date startDate = null;
				Date endDate = null;
				if (EncCommonHelper.checkPurePrivilege(request, "NO_EARL_DATA")) {
					allowStart = EncCommonHelper.getEarlDataDate(request);
				}

				SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
				SimpleDateFormat sfl = new SimpleDateFormat("yyyy-MM-dd HH:mm");
				if (json != null && !json.equals("")) {
					startDate = sf.parse(json);
				}

				if (out != null && !out.equals("")) {
					endDate = sf.parse(EncCommonHelper.getNextDateStr(out,
							"yyyy-MM-dd"));
				}

				if (startDate == null) {
					startDate = allowStart;
				} else if (allowStart != null && allowStart.after(startDate)) {
					startDate = allowStart;
				}

				int total = 0;
				BigDecimal cost = new BigDecimal(0);
				List list = this.receiveBillDao.getAppBcListCount(startDate,
						endDate, mapper, bt, tsId, ub, mngId);
				if (list != null && !list.isEmpty() && list.get(0) != null) {
					Object[] perPageNum = (Object[]) list.get(0);
					if (perPageNum[1] != null) {
						total = Integer.parseInt(perPageNum[0].toString());
						cost = (BigDecimal) perPageNum[1];
					}
				}

				map.put("cost", cost);
				map.put("total", Integer.valueOf(total));
				int arg37 = EncCommonHelper.getPageSize(request);
				int pageno = EncCommonHelper.getCurrentPageIndex(request,
						total, arg37);
				if (total > pageno * arg37) {
					map.put("more", "Y");
				} else {
					map.put("more", "N");
				}

				if (showPrev != null && showPrev.equals("Y")) {
					list = this.receiveBillDao.getAppBcList(startDate, endDate,
							mapper, bt, tsId, ub, mngId, 0, pageno * arg37);
				} else {
					list = this.receiveBillDao.getAppBcList(startDate, endDate,
							mapper, bt, tsId, ub, mngId, (pageno - 1) * arg37,
							arg37);
				}

				List baList = this.bankAccountDao.getList("", "");
				ArrayList items = new ArrayList();

				for (int tmpList = 0; tmpList < list.size(); ++tmpList) {
					Object[] tsItems = (Object[]) list.get(tmpList);
					String i = (String) tsItems[1];
					String item = "";
					String ts = (String) tsItems[2];
					if (ts != null && !ts.equals("")) {
						i = i + "(" + ts + ")";
					}

					if (tsItems[8] != null) {
						item = sfl.format((Date) tsItems[8]);
					}

					HashMap item1 = new HashMap();
					item1.put("id", tsItems[0]);
					item1.put("estName", i);
					item1.put("type", tsItems[3]);
					item1.put("cost", tsItems[4]);
					item1.put(
							"ba",
							EncCommonHelper.getSimpleObjectName(baList,
									Long.parseLong(tsItems[5].toString())));
					item1.put("date", sf.format((Date) tsItems[6]));
					item1.put("creaName", tsItems[7]);
					item1.put("creaTime", item);
					items.add(item1);
				}

				map.put("items", items);
				if (initQuer != null && initQuer.equals("Y")) {
					List arg38 = PageHelper.getTallySetList(this.tallySetDao,
							ub);
					ArrayList arg39 = new ArrayList();

					for (int arg40 = 0; arg40 < arg38.size(); ++arg40) {
						HashMap arg41 = new HashMap();
						TallySet arg42 = (TallySet) arg38.get(arg40);
						arg41.put("id", Long.valueOf(arg42.getId()));
						arg41.put("name", arg42.getTitle());
						arg39.add(arg41);
					}

					map.put("tsItems", arg39);
				}

				map.put("status", "OK");
				map.put("errMsg", "");
			} catch (Exception arg34) {
				map.put("status", "ERROR");
				map.put("errMsg", arg34.toString());
			}
		}

		response.setContentType("text/plain");
		response.setCharacterEncoding("utf-8");
		response.setHeader("Cache-Control", "no-cache");
		response.setHeader("Pragma", "no-cache");
		ObjectMapper arg35 = new ObjectMapper();
		json = arg35.writeValueAsString(map);
		ServletOutputStream arg36 = response.getOutputStream();
		arg36.write(json.getBytes("utf-8"));
		arg36.flush();
		arg36.close();
		return null;
	}

	public ModelAndView handleAppBcInfo(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		HashMap map = new HashMap();

		try {
			long mapper = Long.parseLong(request.getParameter("id"));
			String out = request.getParameter("type");
			long baId = 0L;
			long estId = 0L;
			long depId = 0L;
			long tsId = 0L;
			String bankName = "";
			String depName = "";
			String estName = "";
			String date = "";
			String code = "";
			String desc = "";
			String mngName = "";
			String mark = "";
			String creaName = "";
			String creaTime = "";
			String tsName = "";
			String examName = "";
			String examTime = "";
			new BigDecimal(0);
			SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
			SimpleDateFormat sfl = new SimpleDateFormat("yyyy-MM-dd HH:mm");
			BigDecimal cost;
			if (out.equals("BUSI")) {
				BusinessBill est = (BusinessBill) this.receiveBillDao.get(
						BusinessBill.class, mapper);
				BusinessBillExt ts = (BusinessBillExt) this.receiveBillDao.get(
						BusinessBillExt.class, mapper);
				baId = est.getBankAccountId();
				estId = est.getClientId();
				depId = est.getDepartmentId();
				code = est.getBillCode();
				date = sf.format(est.getOrderDate());
				cost = est.getCost();
				mngName = est.getManagerName();
				mark = PageHelper.parseNull(est.getMark());
				desc = PageHelper.parseNull(est.getContent());
				creaName = est.getCreaterName();
				if (est.getCreateTime() != null) {
					creaTime = sfl.format(est.getCreateTime());
				}

				if (ts.getExamined().equals("Y")) {
					examName = ts.getExaminerName();
					if (ts.getExamineTime() != null) {
						examTime = sfl.format(ts.getExamineTime());
					}
				}

				tsId = est.getTallySetId();
			} else {
				ReceiveBill est1 = (ReceiveBill) this.receiveBillDao.get(
						ReceiveBill.class, mapper);
				baId = est1.getBankAccountId();
				estId = est1.getClientId();
				depId = est1.getDepartmentId();
				code = est1.getBillCode();
				date = sf.format(est1.getReceiveDate());
				cost = est1.getCost();
				mngName = est1.getManagerName();
				mark = PageHelper.parseNull(est1.getMark());
				desc = PageHelper.parseNull(est1.getDescription());
				creaName = est1.getCreaterName();
				if (est1.getCreateTime() != null) {
					creaTime = sfl.format(est1.getCreateTime());
				}

				if (est1.getExamined().equals("Y")) {
					examName = est1.getExaminerName();
					if (est1.getExamineTime() != null) {
						examTime = sfl.format(est1.getExamineTime());
					}
				}

				tsId = est1.getTallySetId();
			}

			if (baId != 0L) {
				BankAccount est2 = (BankAccount) this.receiveBillDao.get(
						BankAccount.class, baId);
				if (est2 != null) {
					bankName = est2.getBankName();
				}
			}

			if (depId != 0L) {
				Department est3 = (Department) this.receiveBillDao.get(
						Department.class, depId);
				if (est3 != null) {
					depName = est3.getDepartmentName();
				}
			}

			Establishment est4 = (Establishment) this.receiveBillDao.get(
					Establishment.class, estId);
			if (est4 != null) {
				estName = est4.getEstName();
			}

			TallySet ts1 = (TallySet) this.receiveBillDao.get(TallySet.class,
					tsId);
			if (ts1 != null) {
				tsName = ts1.getTitle();
			}

			map.put("estName", estName);
			map.put("code", code);
			map.put("date", date);
			map.put("desc", desc);
			map.put("cost", cost);
			map.put("ba", bankName);
			map.put("mngName", mngName);
			map.put("depName", depName);
			map.put("mark", mark);
			map.put("creaName", creaName);
			map.put("creaTime", creaTime);
			map.put("examName", examName);
			map.put("examTime", examTime);
			map.put("tsName", tsName);
			map.put("type", out);
			map.put("status", "OK");
			map.put("errMsg", "");
		} catch (Exception arg32) {
			map.put("status", "ERROR");
			map.put("errMsg", arg32.toString());
		}

		response.setContentType("text/plain");
		response.setCharacterEncoding("utf-8");
		response.setHeader("Cache-Control", "no-cache");
		response.setHeader("Pragma", "no-cache");
		ObjectMapper mapper1 = new ObjectMapper();
		String json = mapper1.writeValueAsString(map);
		ServletOutputStream out1 = response.getOutputStream();
		out1.write(json.getBytes("utf-8"));
		out1.flush();
		out1.close();
		return null;
	}

	public ModelAndView handleAppListForExam(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		HashMap map = new HashMap();
		UserStatus s = EncInterceptorHelper.checkAppUserSignon(request);
		UserBean ub = s.getUserBean();
		String json;
		if (ub == null) {
			map.put("status", "NO_LOGIN");
			map.put("errMsg", "");
		} else if (!EncCommonHelper.checkPrivilege(request, "RECE_EXAM")) {
			map.put("status", "ERROR");
			map.put("errMsg", "您还没有此功能的使用权限，请确认返回！");
		} else {
			try {
				String mapper = request.getParameter("sk");
				json = request.getParameter("ts_id");
				String out = request.getParameter("show_prev");
				String initQuer = request.getParameter("init_quer");
				long mngId = 0L;
				long tsId = 0L;
				if (json != null && !json.equals("")) {
					tsId = Long.parseLong(json);
				}

				if (EncCommonHelper.checkPurePrivilege(request, "BUSI_SELF")) {
					mngId = ub.getStaffer().getId();
				}

				Date allowStart = null;
				if (EncCommonHelper.checkPurePrivilege(request, "NO_EARL_DATA")) {
					allowStart = EncCommonHelper.getEarlDataDate(request);
				}

				int total = 0;
				BigDecimal cost = new BigDecimal(0);
				List list = this.receiveBillDao.getAppListForExamCount(mapper,
						tsId, ub, allowStart, mngId);
				if (list != null && !list.isEmpty() && list.get(0) != null) {
					Object[] perPageNum = (Object[]) list.get(0);
					if (perPageNum[1] != null) {
						total = Integer.parseInt(perPageNum[0].toString());
						cost = (BigDecimal) perPageNum[1];
					}
				}

				map.put("cost", cost);
				map.put("total", Integer.valueOf(total));
				int arg31 = EncCommonHelper.getPageSize(request);
				int pageno = EncCommonHelper.getCurrentPageIndex(request,
						total, arg31);
				if (total > pageno * arg31) {
					map.put("more", "Y");
				} else {
					map.put("more", "N");
				}

				if (out != null && out.equals("Y")) {
					list = this.receiveBillDao.getAppListForExam(mapper, tsId,
							ub, allowStart, mngId, 0, pageno * arg31);
				} else {
					list = this.receiveBillDao.getAppListForExam(mapper, tsId,
							ub, allowStart, mngId, (pageno - 1) * arg31, arg31);
				}

				SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
				SimpleDateFormat sfl = new SimpleDateFormat("yyyy-MM-dd HH:mm");
				ArrayList items = new ArrayList();

				for (int tmpList = 0; tmpList < list.size(); ++tmpList) {
					Object[] tsItems = (Object[]) list.get(tmpList);
					ReceiveBill i = (ReceiveBill) tsItems[0];
					String item = (String) tsItems[1];
					String ts = "";
					if (i.getCreateTime() != null) {
						ts = sfl.format(i.getCreateTime());
					}

					HashMap item1 = new HashMap();
					item1.put("cost", i.getCost());
					item1.put("creaName", i.getCreaterName());
					item1.put("creaTime", ts);
					item1.put("estName", item);
					item1.put("id", Long.valueOf(i.getId()));
					item1.put("date", sf.format(i.getReceiveDate()));
					items.add(item1);
				}

				map.put("items", items);
				if (initQuer != null && initQuer.equals("Y")) {
					List arg32 = PageHelper.getTallySetList(this.tallySetDao,
							ub);
					ArrayList arg33 = new ArrayList();

					for (int arg34 = 0; arg34 < arg32.size(); ++arg34) {
						HashMap arg35 = new HashMap();
						TallySet arg36 = (TallySet) arg32.get(arg34);
						arg35.put("id", Long.valueOf(arg36.getId()));
						arg35.put("name", arg36.getTitle());
						arg33.add(arg35);
					}

					map.put("tsItems", arg33);
				}

				map.put("status", "OK");
				map.put("errMsg", "");
			} catch (Exception arg28) {
				map.put("status", "ERROR");
				map.put("errMsg", arg28.toString());
			}
		}

		response.setContentType("text/plain");
		response.setCharacterEncoding("utf-8");
		response.setHeader("Cache-Control", "no-cache");
		response.setHeader("Pragma", "no-cache");
		ObjectMapper arg29 = new ObjectMapper();
		json = arg29.writeValueAsString(map);
		ServletOutputStream arg30 = response.getOutputStream();
		arg30.write(json.getBytes("utf-8"));
		arg30.flush();
		arg30.close();
		return null;
	}

	public ModelAndView handleAppListForUnExam(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		HashMap map = new HashMap();
		UserStatus s = EncInterceptorHelper.checkAppUserSignon(request);
		UserBean ub = s.getUserBean();
		String json;
		if (ub == null) {
			map.put("status", "NO_LOGIN");
			map.put("errMsg", "");
		} else if (!EncCommonHelper.checkPrivilege(request, "RECE_UN_EXAM")) {
			map.put("status", "ERROR");
			map.put("errMsg", "您还没有此功能的使用权限，请确认返回！");
		} else {
			try {
				String mapper = request.getParameter("sk");
				json = request.getParameter("ts_id");
				String out = request.getParameter("show_prev");
				String initQuer = request.getParameter("init_quer");
				long mngId = 0L;
				long tsId = 0L;
				if (json != null && !json.equals("")) {
					tsId = Long.parseLong(json);
				}

				if (EncCommonHelper.checkPurePrivilege(request, "BUSI_SELF")) {
					mngId = ub.getStaffer().getId();
				}

				Date allowStart = null;
				if (EncCommonHelper.checkPurePrivilege(request, "NO_EARL_DATA")) {
					allowStart = EncCommonHelper.getEarlDataDate(request);
				}

				int total = 0;
				BigDecimal cost = new BigDecimal(0);
				List list = this.receiveBillDao.getAppListForUnExamCount(
						mapper, tsId, ub, allowStart, mngId);
				if (list != null && !list.isEmpty() && list.get(0) != null) {
					Object[] perPageNum = (Object[]) list.get(0);
					if (perPageNum[1] != null) {
						total = Integer.parseInt(perPageNum[0].toString());
						cost = (BigDecimal) perPageNum[1];
					}
				}

				map.put("cost", cost);
				int arg31 = EncCommonHelper.getPageSize(request);
				int pageno = EncCommonHelper.getCurrentPageIndex(request,
						total, arg31);
				if (total > pageno * arg31) {
					map.put("more", "Y");
				} else {
					map.put("more", "N");
				}

				if (out != null && out.equals("Y")) {
					list = this.receiveBillDao.getAppListForUnExam(mapper,
							tsId, ub, allowStart, mngId, 0, pageno * arg31);
				} else {
					list = this.receiveBillDao.getAppListForUnExam(mapper,
							tsId, ub, allowStart, mngId, (pageno - 1) * arg31,
							arg31);
				}

				SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
				SimpleDateFormat sfl = new SimpleDateFormat("yyyy-MM-dd HH:mm");
				ArrayList items = new ArrayList();

				for (int tmpList = 0; tmpList < list.size(); ++tmpList) {
					Object[] tsItems = (Object[]) list.get(tmpList);
					ReceiveBill i = (ReceiveBill) tsItems[0];
					String item = (String) tsItems[1];
					String ts = "";
					if (i.getExamineTime() != null) {
						ts = sfl.format(i.getExamineTime());
					}

					HashMap item1 = new HashMap();
					item1.put("cost", i.getCost());
					item1.put("examName", i.getExaminerName());
					item1.put("examTime", ts);
					item1.put("estName", item);
					item1.put("id", Long.valueOf(i.getId()));
					item1.put("date", sf.format(i.getReceiveDate()));
					items.add(item1);
				}

				map.put("items", items);
				if (initQuer != null && initQuer.equals("Y")) {
					List arg32 = PageHelper.getTallySetList(this.tallySetDao,
							ub);
					ArrayList arg33 = new ArrayList();

					for (int arg34 = 0; arg34 < arg32.size(); ++arg34) {
						HashMap arg35 = new HashMap();
						TallySet arg36 = (TallySet) arg32.get(arg34);
						arg35.put("id", Long.valueOf(arg36.getId()));
						arg35.put("name", arg36.getTitle());
						arg33.add(arg35);
					}

					map.put("tsItems", arg33);
				}

				map.put("status", "OK");
				map.put("errMsg", "");
			} catch (Exception arg28) {
				map.put("status", "ERROR");
				map.put("errMsg", arg28.toString());
			}
		}

		response.setContentType("text/plain");
		response.setCharacterEncoding("utf-8");
		response.setHeader("Cache-Control", "no-cache");
		response.setHeader("Pragma", "no-cache");
		ObjectMapper arg29 = new ObjectMapper();
		json = arg29.writeValueAsString(map);
		ServletOutputStream arg30 = response.getOutputStream();
		arg30.write(json.getBytes("utf-8"));
		arg30.flush();
		arg30.close();
		return null;
	}

	public ModelAndView handleAppInfo(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		HashMap map = new HashMap();

		try {
			long mapper = Long.parseLong(request.getParameter("id"));
			ReceiveBill out = (ReceiveBill) this.receiveBillDao.get(
					ReceiveBill.class, mapper);
			SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
			SimpleDateFormat sfl = new SimpleDateFormat("yyyy-MM-dd HH:mm");
			String bankName = "";
			String depName = "";
			String estName = "";
			String tsName = "";
			String creaTime = "";
			if (out.getBankAccountId() != 0L) {
				BankAccount est = (BankAccount) this.receiveBillDao.get(
						BankAccount.class, out.getBankAccountId());
				if (est != null) {
					bankName = est.getBankName();
					if (est.getAccountName() != null
							&& !est.getAccountName().equals("")) {
						bankName = bankName + "(" + est.getAccountName() + ")";
					}
				}
			}

			if (out.getDepartmentId() != 0L) {
				Department est1 = (Department) this.receiveBillDao.get(
						Department.class, out.getDepartmentId());
				if (est1 != null) {
					depName = est1.getDepartmentName();
				}
			}

			Establishment est2 = (Establishment) this.receiveBillDao.get(
					Establishment.class, out.getClientId());
			if (est2 != null) {
				estName = est2.getEstName();
			}

			TallySet ts = (TallySet) this.receiveBillDao.get(TallySet.class,
					out.getTallySetId());
			if (ts != null) {
				tsName = ts.getTitle();
			}

			if (out.getCreateTime() != null) {
				creaTime = sfl.format(out.getCreateTime());
			}

			map.put("estName", estName);
			map.put("code", out.getBillCode());
			map.put("date", sf.format(out.getReceiveDate()));
			map.put("desc", PageHelper.parseNull(out.getDescription()));
			map.put("cost", out.getCost());
			map.put("ba", bankName);
			map.put("mngName", out.getManagerName());
			map.put("depName", depName);
			map.put("mark", PageHelper.parseNull(out.getMark()));
			map.put("creaName", out.getCreaterName());
			map.put("creaTime", creaTime);
			String examName = "";
			String examTime = "";
			if (out.getExamined().equals("Y")) {
				examName = out.getExaminerName();
				if (out.getExamineTime() != null) {
					examTime = sfl.format(out.getExamineTime());
				}
			}

			map.put("exam", out.getExamined());
			map.put("examName", examName);
			map.put("examTime", examTime);
			map.put("tsName", tsName);
			map.put("status", "OK");
			map.put("errMsg", "");
		} catch (Exception arg17) {
			map.put("status", "ERROR");
			map.put("errMsg", arg17.toString());
		}

		response.setContentType("text/plain");
		response.setCharacterEncoding("utf-8");
		response.setHeader("Cache-Control", "no-cache");
		response.setHeader("Pragma", "no-cache");
		ObjectMapper mapper1 = new ObjectMapper();
		String json = mapper1.writeValueAsString(map);
		ServletOutputStream out1 = response.getOutputStream();
		out1.write(json.getBytes("utf-8"));
		out1.flush();
		out1.close();
		return null;
	}

	public ModelAndView handleAppExam(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		UserStatus s = EncInterceptorHelper.checkAppUserSignon(request);
		UserBean ub = s.getUserBean();
		String status = "";
		String errMsg = "";
		if (ub == null) {
			status = "NO_LOGIN";
		} else {
			String map = request.getParameter("type");
			String mapper = request.getParameter("id");
			if (map != null && map.equals("UNEXAM")) {
				if (!EncCommonHelper.checkPrivilege(request, "RECE_UN_EXAM")) {
					status = "ERROR";
					errMsg = "您还没有此功能的使用权限，请确认返回！";
				} else {
					try {
						this.receiveBillService.txUnExamine(
								Long.parseLong(mapper), this.receiveBillDao,
								this.receiveBillItemDao, this.businessBillDao,
								this.adjustBillDao, this.bankAccountBalanceDao,
								this.bankAccountDetailDao,
								this.financeDetailDao, this.idGenerator, ub);
						status = "OK";
					} catch (CannotAcquireLockException arg14) {
						status = "ERROR";
						errMsg = "事务冲突故障，请重新操作！";
					} catch (NotAllowException arg15) {
						status = "ERROR";
						errMsg = arg15.getMessage();
					}
				}
			} else if (!EncCommonHelper.checkPrivilege(request, "RECE_EXAM")) {
				status = "ERROR";
				errMsg = "您还没有此功能的使用权限，请确认返回！";
			} else {
				long json = ub.getStaffer().getId();
				String examinerName = ub.getStaffer().getStafferName();

				try {
					this.receiveBillService.txExamine(Long.parseLong(mapper),
							this.receiveBillDao, this.receiveBillItemDao,
							this.businessBillDao, this.adjustBillDao, json,
							examinerName, this.bankAccountBalanceDao,
							this.idGenerator);
					status = "OK";
				} catch (NotAllowException arg12) {
					status = "ERROR";
					errMsg = arg12.getMessage();
				} catch (CannotAcquireLockException arg13) {
					status = "ERROR";
					errMsg = "事务冲突故障，请重新操作！";
				}
			}
		}

		HashMap map1 = new HashMap();
		map1.put("status", status);
		map1.put("errMsg", errMsg);
		ObjectMapper mapper1 = new ObjectMapper();
		String json1 = mapper1.writeValueAsString(map1);
		ServletOutputStream out = response.getOutputStream();
		out.write(json1.getBytes("utf-8"));
		out.flush();
		out.close();
		return null;
	}

	public ModelAndView handleAppNew(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		HashMap map = new HashMap();
		UserStatus s = EncInterceptorHelper.checkAppUserSignon(request);
		UserBean ub = s.getUserBean();
		String status = "";
		String errMsg = "";
		if (ub == null) {
			status = "NO_LOGIN";
		} else {
			String mapper = request.getParameter("bb_code");
			if (!EncCommonHelper.checkPrivilege(request, "RECE_NEW")) {
				status = "ERROR";
				errMsg = "您还没有此功能的使用权限，请确认返回！";
			} else {
				CodeRule json = this.codeRuleDao.get("RECEIVE_BILL");

				try {
					String out = this.receiveBillService.txInsertApp(mapper,
							ub, json, this.receiveBillDao,
							this.businessBillDao, this.bankAccountBalanceDao,
							this.serialNumberDao, this.idGenerator);
					map.put("billCode", out);
					status = "OK";
				} catch (NotAllowException arg10) {
					status = "ERROR";
					errMsg = arg10.getMessage();
				} catch (CannotAcquireLockException arg11) {
					status = "ERROR";
					errMsg = "事务冲突故障，请重新操作！";
				}
			}
		}

		map.put("status", status);
		map.put("errMsg", errMsg);
		ObjectMapper mapper1 = new ObjectMapper();
		String json1 = mapper1.writeValueAsString(map);
		ServletOutputStream out1 = response.getOutputStream();
		out1.write(json1.getBytes("utf-8"));
		out1.flush();
		out1.close();
		return null;
	}

	public ModelAndView handleAppList(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		HashMap map = new HashMap();
		UserStatus s = EncInterceptorHelper.checkAppUserSignon(request);
		UserBean ub = s.getUserBean();
		String json;
		if (ub == null) {
			map.put("status", "NO_LOGIN");
			map.put("errMsg", "");
		} else if (!EncCommonHelper.checkPrivilege(request, "RECE_BILL_SEAR")) {
			map.put("status", "ERROR");
			map.put("errMsg", "您还没有此功能的使用权限，请确认返回！");
		} else {
			try {
				String mapper = request.getParameter("est_name");
				json = request.getParameter("start_date");
				String out = request.getParameter("end_date");
				String baIdStr = request.getParameter("ba_id");
				String tsIdStr = request.getParameter("ts_id");
				String orde = request.getParameter("orde");
				String showPrev = request.getParameter("show_prev");
				String initQuer = request.getParameter("init_quer");
				long baId = 0L;
				long tsId = 0L;
				long mngId = 0L;
				if (baIdStr != null && !baIdStr.equals("")) {
					baId = Long.parseLong(baIdStr);
				}

				if (tsIdStr != null && !tsIdStr.equals("")) {
					tsId = Long.parseLong(tsIdStr);
				}

				if (EncCommonHelper.checkPurePrivilege(request, "BUSI_SELF")) {
					mngId = ub.getStaffer().getId();
				}

				Date allowStart = null;
				Date startDate = null;
				Date endDate = null;
				if (EncCommonHelper.checkPurePrivilege(request, "NO_EARL_DATA")) {
					allowStart = EncCommonHelper.getEarlDataDate(request);
				}

				SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
				SimpleDateFormat sfl = new SimpleDateFormat("yyyy-MM-dd HH:mm");
				if (json != null && !json.equals("")) {
					startDate = sf.parse(json);
				}

				if (out != null && !out.equals("")) {
					endDate = sf.parse(EncCommonHelper.getNextDateStr(out,
							"yyyy-MM-dd"));
				}

				if (startDate == null) {
					startDate = allowStart;
				} else if (allowStart != null && allowStart.after(startDate)) {
					startDate = allowStart;
				}

				if (orde == null || orde.equals("")) {
					orde = "RECE_DATE";
				}

				int total = 0;
				BigDecimal cost = new BigDecimal(0);
				List list = this.receiveBillDao.getAppListCount(startDate,
						endDate, mapper, baId, tsId, ub, mngId);
				if (list != null && !list.isEmpty() && list.get(0) != null) {
					Object[] perPageNum = (Object[]) list.get(0);
					if (perPageNum[1] != null) {
						total = Integer.parseInt(perPageNum[0].toString());
						cost = (BigDecimal) perPageNum[1];
					}
				}

				map.put("cost", cost);
				map.put("total", Integer.valueOf(total));
				int arg43 = EncCommonHelper.getPageSize(request);
				int pageno = EncCommonHelper.getCurrentPageIndex(request,
						total, arg43);
				if (total > pageno * arg43) {
					map.put("more", "Y");
				} else {
					map.put("more", "N");
				}

				if (showPrev != null && showPrev.equals("Y")) {
					list = this.receiveBillDao.getAppList(startDate, endDate,
							mapper, baId, tsId, ub, mngId, orde, 0, pageno
									* arg43);
				} else {
					list = this.receiveBillDao.getAppList(startDate, endDate,
							mapper, baId, tsId, ub, mngId, orde, (pageno - 1)
									* arg43, arg43);
				}

				List baList = this.bankAccountDao.getList("", "");
				ArrayList items = new ArrayList();

				String ts;
				for (int ent = 0; ent < list.size(); ++ent) {
					HashMap tmpList = new HashMap();
					Object[] baItems = (Object[]) list.get(ent);
					ReceiveBill tsItems = (ReceiveBill) baItems[0];
					String i = (String) baItems[1];
					String item = "";
					ts = "";
					if (tsItems.getCreateTime() != null) {
						item = sfl.format(tsItems.getCreateTime());
					}

					if (tsItems.getBankAccountId() != 0L) {
						for (int j = 0; j < baList.size(); ++j) {
							BankAccount ba = (BankAccount) baList.get(j);
							if (ba.getId() == tsItems.getBankAccountId()) {
								ts = ba.getBankName();
								if (ba.getAccountName() != null
										&& !ba.getAccountName().equals("")) {
									ts = ts + "(" + ba.getAccountName() + ")";
								}
								break;
							}
						}
					}

					tmpList.put("id", Long.valueOf(tsItems.getId()));
					tmpList.put("estName", i);
					tmpList.put("cost", tsItems.getCost());
					tmpList.put("date", sf.format(tsItems.getReceiveDate()));
					tmpList.put("baName", ts);
					tmpList.put("creaName", tsItems.getCreaterName());
					tmpList.put("creaTime", item);
					tmpList.put("desc",
							PageHelper.parseNull(tsItems.getDescription()));
					if (tsItems.getExamined().equals("Y")) {
						tmpList.put("stat", "EXAM");
					} else {
						tmpList.put("stat", "UNEXAM");
					}

					items.add(tmpList);
				}

				map.put("items", items);
				if (initQuer != null && initQuer.equals("Y")) {
					EnterpriseInfo arg44 = EncCommonHelper
							.getEnterpriseInfo(request);
					List arg45 = PageHelper.parseBaList(baList, arg44, ub, 0L,
							0L);
					ArrayList arg46 = new ArrayList();

					for (int arg47 = 0; arg47 < arg45.size(); ++arg47) {
						HashMap arg49 = new HashMap();
						BankAccount arg51 = (BankAccount) arg45.get(arg47);
						ts = arg51.getBankName();
						if (arg51.getAccountName() != null
								&& !arg51.getAccountName().equals("")) {
							ts = ts + "(" + arg51.getAccountName() + ")";
						}

						arg49.put("id", Long.valueOf(arg51.getId()));
						arg49.put("name", ts);
						arg46.add(arg49);
					}

					arg45 = PageHelper.getTallySetList(this.tallySetDao, ub);
					ArrayList arg48 = new ArrayList();

					for (int arg50 = 0; arg50 < arg45.size(); ++arg50) {
						HashMap arg52 = new HashMap();
						TallySet arg53 = (TallySet) arg45.get(arg50);
						arg52.put("id", Long.valueOf(arg53.getId()));
						arg52.put("name", arg53.getTitle());
						arg48.add(arg52);
					}

					map.put("baItems", arg46);
					map.put("tsItems", arg48);
				}

				map.put("status", "OK");
				map.put("errMsg", "");
			} catch (Exception arg40) {
				map.put("status", "ERROR");
				map.put("errMsg", arg40.toString());
			}
		}

		response.setContentType("text/plain");
		response.setCharacterEncoding("utf-8");
		response.setHeader("Cache-Control", "no-cache");
		response.setHeader("Pragma", "no-cache");
		ObjectMapper arg41 = new ObjectMapper();
		json = arg41.writeValueAsString(map);
		ServletOutputStream arg42 = response.getOutputStream();
		arg42.write(json.getBytes("utf-8"));
		arg42.flush();
		arg42.close();
		return null;
	}

	public String getDialogSuccessView() {
		return this.dialogSuccessView;
	}

	public void setDialogSuccessView(String dialogSuccessView) {
		this.dialogSuccessView = dialogSuccessView;
	}

	public BusinessBillDao getBusinessBillDao() {
		return this.businessBillDao;
	}

	public void setBusinessBillDao(BusinessBillDao businessBillDao) {
		this.businessBillDao = businessBillDao;
	}

	public ReceiveBillDao getReceiveBillDao() {
		return this.receiveBillDao;
	}

	public void setReceiveBillDao(ReceiveBillDao receiveBillDao) {
		this.receiveBillDao = receiveBillDao;
	}

	public ReceiveBillItemDao getReceiveBillItemDao() {
		return this.receiveBillItemDao;
	}

	public void setReceiveBillItemDao(ReceiveBillItemDao receiveBillItemDao) {
		this.receiveBillItemDao = receiveBillItemDao;
	}

	public String getInfoForExamineView() {
		return this.infoForExamineView;
	}

	public void setInfoForExamineView(String infoForExamineView) {
		this.infoForExamineView = infoForExamineView;
	}

	public String getInfoForUnExamineView() {
		return this.infoForUnExamineView;
	}

	public void setInfoForUnExamineView(String infoForUnExamineView) {
		this.infoForUnExamineView = infoForUnExamineView;
	}

	public String getListForExamineView() {
		return this.listForExamineView;
	}

	public void setListForExamineView(String listForExamineView) {
		this.listForExamineView = listForExamineView;
	}

	public String getListForUnExamineView() {
		return this.listForUnExamineView;
	}

	public void setListForUnExamineView(String listForUnExamineView) {
		this.listForUnExamineView = listForUnExamineView;
	}

	public String getSearchResultView() {
		return this.searchResultView;
	}

	public void setSearchResultView(String searchResultView) {
		this.searchResultView = searchResultView;
	}

	public DepartmentDao getDepartmentDao() {
		return this.departmentDao;
	}

	public void setDepartmentDao(DepartmentDao departmentDao) {
		this.departmentDao = departmentDao;
	}

	public QueryDao getQueryDao() {
		return this.queryDao;
	}

	public void setQueryDao(QueryDao queryDao) {
		this.queryDao = queryDao;
	}

	public AdjustBillDao getAdjustBillDao() {
		return this.adjustBillDao;
	}

	public void setAdjustBillDao(AdjustBillDao adjustBillDao) {
		this.adjustBillDao = adjustBillDao;
	}

	public String getFinanceListForClientView() {
		return this.financeListForClientView;
	}

	public void setFinanceListForClientView(String financeListForClientView) {
		this.financeListForClientView = financeListForClientView;
	}

	public String getItemListForBusinessBillView() {
		return this.itemListForBusinessBillView;
	}

	public void setItemListForBusinessBillView(
			String itemListForBusinessBillView) {
		this.itemListForBusinessBillView = itemListForBusinessBillView;
	}

	public String getPrintView() {
		return this.printView;
	}

	public void setPrintView(String printView) {
		this.printView = printView;
	}

	public String getListForEstablishmentView() {
		return this.listForEstablishmentView;
	}

	public void setListForEstablishmentView(String listForEstablishmentView) {
		this.listForEstablishmentView = listForEstablishmentView;
	}

	public String getInfoForCancelView() {
		return this.infoForCancelView;
	}

	public void setInfoForCancelView(String infoForCancelView) {
		this.infoForCancelView = infoForCancelView;
	}

	public String getListForCancelView() {
		return this.listForCancelView;
	}

	public void setListForCancelView(String listForCancelView) {
		this.listForCancelView = listForCancelView;
	}

	public ReceiveBillService getReceiveBillService() {
		return this.receiveBillService;
	}

	public void setReceiveBillService(ReceiveBillService receiveBillService) {
		this.receiveBillService = receiveBillService;
	}

	public DataSource getDataSource() {
		return this.dataSource;
	}

	public void setDataSource(DataSource dataSource) {
		this.dataSource = dataSource;
	}

	public String getBackCostListView() {
		return this.backCostListView;
	}

	public void setBackCostListView(String backCostListView) {
		this.backCostListView = backCostListView;
	}

	public BankAccountBalanceDao getBankAccountBalanceDao() {
		return this.bankAccountBalanceDao;
	}

	public void setBankAccountBalanceDao(
			BankAccountBalanceDao bankAccountBalanceDao) {
		this.bankAccountBalanceDao = bankAccountBalanceDao;
	}

	public BankAccountDetailDao getBankAccountDetailDao() {
		return this.bankAccountDetailDao;
	}

	public void setBankAccountDetailDao(
			BankAccountDetailDao bankAccountDetailDao) {
		this.bankAccountDetailDao = bankAccountDetailDao;
	}

	public IdGenerator getIdGenerator() {
		return this.idGenerator;
	}

	public void setIdGenerator(IdGenerator idGenerator) {
		this.idGenerator = idGenerator;
	}

	public PayModeDao getPayModeDao() {
		return this.payModeDao;
	}

	public void setPayModeDao(PayModeDao payModeDao) {
		this.payModeDao = payModeDao;
	}

	public TallySetDao getTallySetDao() {
		return this.tallySetDao;
	}

	public void setTallySetDao(TallySetDao tallySetDao) {
		this.tallySetDao = tallySetDao;
	}

	public BankAccountDao getBankAccountDao() {
		return this.bankAccountDao;
	}

	public void setBankAccountDao(BankAccountDao bankAccountDao) {
		this.bankAccountDao = bankAccountDao;
	}

	public String getBackCostListPrintView() {
		return this.backCostListPrintView;
	}

	public void setBackCostListPrintView(String backCostListPrintView) {
		this.backCostListPrintView = backCostListPrintView;
	}

	public CodeRuleDao getCodeRuleDao() {
		return this.codeRuleDao;
	}

	public void setCodeRuleDao(CodeRuleDao codeRuleDao) {
		this.codeRuleDao = codeRuleDao;
	}

	public FinanceDetailDao getFinanceDetailDao() {
		return this.financeDetailDao;
	}

	public void setFinanceDetailDao(FinanceDetailDao financeDetailDao) {
		this.financeDetailDao = financeDetailDao;
	}
}